package com.ticket.sass.ticketserver.business

import com.ticket.sass.common.ticketserver.dto.output.*
import com.ticket.sass.ticketserver.dto.input.*
import com.ticket.sass.ticketserver.manager.TicketServerManager
import com.ticket.sass.common.ticketserver.dto.input.OrderTicketSubmitInput as TicketServerOrderTicketSubmitInput
import com.ticket.sass.common.ticketserver.dto.input.OrderTicketStatusInput as TicketServerOrderTicketStatusInput
import com.ticket.sass.common.ticketserver.dto.input.OrderTicketInfoInput as TicketServerOrderTicketInfoInput
import com.ticket.sass.common.ticketserver.dto.input.OrderTicketRefundInput as TicketServerOrderTicketRefundInput
import com.ticket.sass.common.ticketserver.dto.input.SeatLockInput as TicketServerSeatLockInput
import com.ticket.sass.common.ticketserver.dto.input.SeatUnlockInput as TicketServerSeatUnlockInput
import org.springframework.stereotype.Component


/**
 * @author 朱其鹏
 * @date 2024/4/13 19:05
 */
@Component
class TradeBusiness(
    private val ticketServerManager: TicketServerManager,
) {
    fun seatLock(input: SeatLockInput): SeatLockOutput {
        return ticketServerManager.api.seatLock(TicketServerSeatLockInput(
            input.outLockNo,
            input.sessionCode,
            input.scheduleKey,
            input.seatList.map {
                TicketServerSeatLockInput.Seat(it.id, it.code)
            }
        ))
    }

    fun seatUnlock(input: SeatUnlockInput): SeatUnlockOutput {
        return ticketServerManager.api.seatUnlock(TicketServerSeatUnlockInput(
            input.id,
            input.scheduleCode,
            input.scheduleKey,
            input.seatList.map {
                TicketServerSeatUnlockInput.Seat(it.id, it.code)
            }
        ))
    }

    fun orderTicketSubmit(input: OrderTicketSubmitInput): OrderTicketSubmitOutput {
        return ticketServerManager.api.orderTicketSubmit(
            TicketServerOrderTicketSubmitInput(
                input.orderNo,
                input.outOrderNo,
                input.sessionCode,
                input.scheduleId,
                input.scheduleUpdateTime,
                input.cellphone,
                input.seatList.map {
                    TicketServerOrderTicketSubmitInput.Seat(
                        it.id,
                        it.code,
                        it.price,
                        it.handleFee,
                        it.serviceFee,
                        it.channelServiceFee
                    )
                },
            )
        )
    }

    fun orderTicketStatus(input: OrderTicketStatusInput): OrderTicketStatusOutput {
        return ticketServerManager.api.orderTicketStatus(TicketServerOrderTicketStatusInput(
            input.orderNo,
            input.outOrderNo,
        ))
    }

    fun orderTicketInfo(code: String): OrderTicketInfoOutput {
        return ticketServerManager.api.orderTicketInfo(TicketServerOrderTicketInfoInput(code))
    }

    fun orderTicketRefund(input: OrderTicketRefundInput): OrderTicketRefundOutput {
        return ticketServerManager.api.orderTicketRefund(TicketServerOrderTicketRefundInput(
            input.code,
            input.orderNo,
            input.sessionCode,
            input.seatList.map {
                TicketServerOrderTicketRefundInput.Seat(it.id, it.code)
            },
        ))
    }
}
